package com.pp.small.user.controller;

import com.pp.small.common.base.BaseResult;
import com.pp.small.common.context.UserContext;
import com.pp.small.common.enums.ResponseEnum;
import com.pp.small.user.entity.User;
import com.pp.small.user.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author pzh
 * @since 2024-12-11 16:02:28
 */
@Tag(name = "用户相关", description = "这是用户相关接口")
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/list")
    @Operation(summary = "获取所有用户" , description = "获取所有用户")
    public BaseResult<List<User>> getByAddrId() {
        log.info("获取所有用户");
        Long userId = UserContext.getUserId();
        if (userId == 0L) {
            return BaseResult.fail(ResponseEnum.UNAUTHORIZED);
        }
        log.info("用户[{}]正在请求数据", userId);

        List<User> users = userService.list();
        return BaseResult.success(users);
    }
}
